<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<#include "/admin/include/head.htm">
<script type="text/javascript">
	$(function(){
		$(".hasChild").click(function(){
			if($(this).val() == "true"){
				$("#goodsType").hide();
				$("#goodsType select").attr("disabled", true);
			}else{
				$("#goodsType").show();
				$("#goodsType select").attr("disabled", false);
			}
		});
		
		$(".hasChild_add").click(function(){
			if($(this).val() == "true"){
				$("#add_goodsType").hide();
				$("#add_goodsType select").attr("disabled", true);
			}else{
				$("#add_goodsType").show();
				$("#add_goodsType select").attr("disabled", false);
			}
		});
	});
	
	//删除商品分类
	function deleteGoodsCategory(){
		jQuery.ligerDialog.confirm('确定删除吗？', function (confirm) {
			if (confirm){
				LG.ajax({
					url: "delete.jhtml",
					data: {"ids": $("#goodsCategory_id").val()},
					success: function(result){
						LG.showSuccess("删除商品分类成功!");
						window.parent.leftFrame.removeNode(result.id);
						if(result.parentId){
							window.location.href="input.jhtml?goodsCategory_id=" + result.parentId;
						}else{
							window.location.href="input.jhtml";
						}				
					},			
					error: function (message) {
					  LG.showError(message);
					}
				});
			}
		});
	}
	
	//添加商品分类
	function add(){
		LG.submitForm($("#childForm"), function(data){
			window.parent.leftFrame.addNode(data, false);
			LG.showSuccess("添加商品分类成功!");
			$("#childForm").clearForm();
		});
	}
	//编辑商品分类
	function edit(){
		LG.submitForm($("#mainform"), function(data){
			window.parent.leftFrame.updateNode(data);
			LG.showSuccess("修改商品分类成功!");
			$("#mainform").clearForm();
		});
	}
	//检验商品类型是否存在
	function checkGoodsType(goodsTypeVal){
		var flag = false;
		if($.trim(goodsTypeVal) == ''){
				return flag;
		}
		$.ajax({
			 url: base + '/admin/b2c/goodsCategory/isExistGoodsTypeName.jhtml',
			 async: false,
             data: { goodsTypeName: goodsTypeVal },
			 type: 'POST',
			 dataType: 'json',
             success: function (result) {
			 	flag = result;
         	 }
		});
		return flag;
	}
</script>
</head>
<#if goodsCategory??>
	<#assign isAdd = true />
<#else>
	<#assign isEdit = true />
</#if>
<body>
<#if isAdd??>
<div id="tabcontainer" style="overflow:hidden;padding:10px;">
	<div class="table_title">
		<img src="${base}/resource/images/communication.gif" />
		<span>修改分类信息 </span>
	</div>
	<form action="update.jhtml" method="post" id="mainform" class="validate">
		<input type="hidden" name="id" value="${(goodsCategory.id)!''}" id="goodsCategory_id"/>
		<table class="table">
			<tr>
				<th>ID:</th>
				<td>${(goodsCategory.id)!''}</td>
			</tr>
			<tr>
				<th>分类编码:</th>
				<td><input type="text" name="code" value="${(goodsCategory.code)!}" 
						class="formText {required: true, remote: 'checkCode.jhtml?oldValue=${(goodsCategory.code)!''}', maxlength:12, minlength:2, messages:{remote: '商品分类编号不能重复!'}}"/>
				</td>
			</tr>
			<tr>
				<th>分类名称:</th>
				<td><input type="text" name="name" value="${(goodsCategory.name)!}" 
						class="formText {required: true, maxlength: 20}"/>
				</td>
			</tr>
			<tr>
				<th>是否有子节点:</th>
				<td><@u.radio name="hasChild" list={'true': '是', 'false':'否'} class="hasChild"
						value="${((goodsCategory.hasChild)?string('true','false'))!'false'}"/>(只能在无子节点的分类上添加商品)
				</td>
			</tr>
			<tr>
				<th>是否推荐:</th>
				<td><@u.radio name="recommend" list={'true': '是', 'false':'否'} 
						value="${((goodsCategory.recommend)?string('true','false'))!'false'}"/>(推荐类别，会在栏目中显示3个)
				</td>
			</tr>
			<tr>
				<th>是否前台可见:</th>
				<td><@u.radio name="showInNav" list={'true': '是', 'false':'否'}
						value="${((goodsCategory.showInNav)?string('true','false'))!'false'}"/>
				</td>
			</tr>
			<tr>
				<th>排序:</th>
				<td>
					<input type="text" name="priority" class="formText {required: true, maxlength: 10, digits: true}" 
						value="${(goodsCategory.priority)!0}" title="只允许输入零或正整数" />
				</td>
			</tr>
			<tr>
				<td colspan="2"><span class="warnInfo">	<span class="icon">&nbsp;</span> 
					温馨提醒：商品分类最多只能创建3级，并且只有达到3级，页面才做展现
					</span>
				</td>
			</tr>
			<tr>
				<th></th>
				<td>
					<#if !update?? || update>
						<input type="button" class="button" value="保存" onclick="edit();"/>
					</#if>
					<#if !delete?? || delete>
						<input type="button" class="button" value="删除" onclick="deleteGoodsCategory();"/>
					</#if>
				</td>
			</tr>
		</table>
	</form>
</div>
</#if>
<#if !goodsCategory?? || goodsCategory.hasChild>
<div id="tabcontainer" style="overflow:hidden;padding:10px;">
	<div class="table_title">
		<img src="${base}/resource/images/communication.gif" />
		<span>添加下属商品分类 </span>
	</div>
	<form action="save.jhtml" method="post" id="childForm" class="validate">
		<table class="table">
			<tr>
				<th>分类编码:</th>
				<td><input type="text" name="code" value="${(goodsCategory.code)!}" 
					class="formText {required: true, remote: 'checkCode.jhtml?oldValue=${(goodsCategory.code)!''}', maxlength:12, minlength:2, messages:{remote: '商品分类编号不能重复!'}}"/>
				</td>
			</tr>
			<tr>
				<th>分类名称:</th>
				<td><input type="text" name="name"
						class="formText {required: true, maxlength: 20}"/>
				</td>
			</tr>
			<tr>
				<th>是否有子节点:</th>
				<td><@u.radio name="hasChild" list={'true': '是', 'false':'否'} class="hasChild_add" value="false"/>(只能在无子节点的分类上添加商品)
				</td>
			</tr>
			<tr>
				<th>是否推荐:</th>
				<td><@u.radio name="recommend" list={'true': '是', 'false':'否'} value="false"/>(推荐类别，会在栏目中显示3个)
				</td>
			</tr>
			<tr>
				<th>是否前台可见:</th>
				<td><@u.radio name="showInNav" list={'true': '是', 'false':'否'} value="true"/>
				</td>
			</tr>
			<tr>
				<th>排序:</th>
				<td>
					<input type="text" name="priority" value="10" class="formText {required: true, maxlength: 10, digits: true}" 
						title="只允许输入零或正整数" />
				</td>
			</tr>
			<tr>
				<td colspan="2"><span class="warnInfo">	<span class="icon">&nbsp;</span> 
					温馨提醒：商品分类最多只能创建3级，并且只有达到3级，页面才做展现
					</span>
				</td>
			</tr>
			<tr>
				<th></th>
				<td><input type="button" class="button" value="添加" onclick="add();"/></td>
			</tr>
		</table>
	</form>
</div>
</#if>
</body>
</html>